<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateCouponOrderHistory extends Migrator
{
    public function up()
    {
        $sql = <<<SQL
CREATE TABLE `coupon_order_history` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `supplier_id` int(11) DEFAULT '0' COMMENT '供应商id',
  `supplier_discount` tinyint(4) NOT NULL DEFAULT '0' COMMENT '供应商结算折扣（%）',
  `supplier_price` int(11) NOT NULL DEFAULT '0' COMMENT '供应商结算价。单位：分',
  `settle_price` int(11) NOT NULL DEFAULT '0' COMMENT '代理商结算价。单位：分',
  `profit` int(11) NOT NULL DEFAULT '0' COMMENT '代理商利润。单位：分',
  `agent_id` int(11) DEFAULT '0' COMMENT '代理商id',
  `settle_type` tinyint(1) DEFAULT '0' COMMENT '代理商结算类型',
  `settle_discount` tinyint(4) NOT NULL DEFAULT '0' COMMENT '结算折扣',
  `platform_profit` int(11) NOT NULL DEFAULT '0' COMMENT '平台利润。单位：分',
  `order_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '平台订单号',
  `out_order_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '第三方订单信息',
  `origin_amount` int(11) DEFAULT '0' COMMENT '原价，单位分',
  `amount` int(11) DEFAULT '0' COMMENT '实际价格，单位分',
  `pay_amount` int(11) DEFAULT '0' COMMENT '实际支付金额 如果没有优惠抵扣的话=price',
  `pay_type` tinyint(1) DEFAULT '0' COMMENT '支付方式',
  `pay_status` tinyint(1) DEFAULT '0' COMMENT '支付状态 0 未支付 1 已支付',
  `pay_time` datetime DEFAULT NULL COMMENT '支付时间',
  `refund_status` tinyint(1) DEFAULT '1' COMMENT '退款状态 1未退款 2退款中 3已退款 ',
  `refund_amount` int(11) DEFAULT '0' COMMENT '退金额 如果是已退款 并且金额小于pay_amount表示部分退款',
  `user_id` int(11) DEFAULT '0' COMMENT '支付用户id',
  `cnid` int(11) DEFAULT '0' COMMENT '渠道id',
  `serv_type` tinyint(1) DEFAULT '0' COMMENT '订单业务类型。不同我业务不同取值。type则是在业务下订单类型的区分',
  `type` tinyint(1) DEFAULT '0' COMMENT '订单类型。业务下订单子类型。比如权益订单，不同权益可能需要不同类型标识',
  `settled_at` datetime DEFAULT NULL COMMENT '结算时间',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted_at` datetime DEFAULT NULL,
  `status` tinyint(4) DEFAULT '0' COMMENT '0未提交 1已提交  2提交失败 3充值成功  4充值失败 5订单处理中 10超时关闭',
  `status_msg` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '状态信息',
  `complete_at` datetime DEFAULT NULL COMMENT '完成时间',
  `supplier_order_sn` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '供应商返回的订单号',
  `agent_settle_status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '结算状态 1无需结算 2待结算 3已结算',
  `card_info` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '卡密信息',
  `account` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '充值账号',
  `product_name` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '产品名称',
  `product_image` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '产品图片',
  `log` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '订单日志',
  `supplier_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '供应商代号',
  `salesman_id` int(11) NOT NULL DEFAULT '0' COMMENT '业务员',
  `order_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '订单创建时间（可能第三方）',
  `ext_data` json DEFAULT NULL COMMENT '扩展信息',
  `title` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '标题',
  `curl_date` datetime DEFAULT NULL COMMENT '订单请求第三方更新的时间',
  `sid` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '自定义标记信息',
  `mobile` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '手机号',
  `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '备注',
  `quote_id` int(11) NOT NULL DEFAULT '0' COMMENT '关联表字段',
  `supplier_status` int(3) NOT NULL DEFAULT '1' COMMENT '1 未提交 2 待提交 4 已提交 6 成功 8 失败 99 轮训 ',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `user_id` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单记录表';


SQL;
        $this->execute($sql);

    }

    public function down()
    {
        $this->table('coupon_order_history')->drop();
    }
}
